< previous page page_381 next page >

Page 381
To prevent these problems, you can simply ignore Scroll events. If you do not redraw the picture during scroll events, Visual Basic generates a final Change event when the user finishes moving the thumb. The program can reposition the world window when it receives this Change event. While the picture does not scroll interactively as the thumb moves, the user can still use the thumb to quickly display other parts of the picture.
Using the SetWorldWindow Subroutine
Individually, the adjustments needed to reposition a world window are simple. Together they add up to a fair amount of code. The SetWorldWindow subroutine shown in the following code adjusts the world window coordinates given by Wxmin, Wxmax, Wymin, and Wymax. The values DataXmin, DataXmax, DataYmin, and DataYmax are the bounds of the picture in world coordinates. The values DataMinWid, DataMaxWid, DataMinHgt, and DataMaxWid are the maximum and minimum dimensions you want to allow for the world window. For instance, you could set DataMaxWid = DataXmax DataXmin plus a 10 percent margin.
This subroutine makes sure that the world window is not ridiculously large or small. It then adjusts the world window's aspect ratio so the data is not distorted. It places the world window in the correct location, maps the world window, and forces it to redraw. Finally, the subroutine sets values for the scrollbar properties Min, Max, SmallChange, and LargeChange.
e10a6a0a59f035e870d90cca05b85fce.gif
' Adjust the world window so it is not too big,
' too small, off to one side, or of the wrong
' aspect ratio. Then map the world window to the
' viewport and force the viewport to repaint.
Private Sub SetWorldWindow()
Dim wid As Single
Dim hgt As Single
Dim xmid As Single
Dim ymid As Single
Dim aspect As Single

    ' Find the size and center of the world window.
    wid = Wxmax - Wxmin
    hgt = Wymax - Wymin
    xmid = (Wxmax + Wxmin) / 2
    ymid = (Wymax + Wymin) / 2

    ' Make sure we're not too big or too small.
    If wid > DataMaxWid Then
        wid = DataMaxWid
    ElseIf wid < DataMinWid Then
        wid = DataMinWid
    End If
    If hgt > DataMaxHgt Then
        hgt = DataMaxHgt
    ElseIf hgt < DataMinHgt Then

 
< previous page page_381 next page >